package com.czf.testmodele.dymamicConnect;

import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zfChen
 * @create 2022/3/21 16:14
 */
@RestController
@Slf4j
public class CzfDataSource {

    public JdbcTemplate jdbcTemplate;

    @RequestMapping("/jdbcTemplate")
    public void connectDataSource(String url, String driverClassName, String userName, String password) {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setUrl(url);
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUsername(userName);
        dataSource.setPassword(password);
        jdbcTemplate = new JdbcTemplate(dataSource);
    }
    /*
    {
      "url": "jdbc:mysql://localhost:3306/hg?serverTimezone=UTC",
      "driverClassName": "com.mysql.cj.jdbc.Driver",
      "userName": "root",
      "password": "123456"
    }
     */

}
